<?php

namespace App\Domain\FamilyMember\Dao;

use App\Domain\FamilyMember\Models\FamilyMemberModel;

class FamilyMemberDao
{

    /**
     * 创建家庭成員
     * @param $params
     * @return FamilyMemberModel
     */
    public function create($params)
    {
        $params = array_filter_null($params);
        return FamilyMemberModel::create($params)->id;
    }

    /**
     * 修改家庭成员
     * @param FamilyMemberModel $model
     * @param $param
     * @return FamilyMemberModel
     */
    public function update(FamilyMemberModel $model, $param)
    {
        $param = array_filter_null($param);
        $model->fill($param)->save();
        return $model;
    }


    public function findById($id)
    {
        return FamilyMemberModel::where('id', $id)->where('state', 1)->first();
    }

    public function findByPhone($phone)
    {
        return FamilyMemberModel::where('phone', $phone)->where('state', 1)->first();
    }

    public function findAll($houseHolder_id)
    {
        return FamilyMemberModel::where('houseHolder_id', $houseHolder_id)->where('state', 1)->get();
    }

    public function findByName($name)
    {
        return FamilyMemberModel::where('name', $name)->where('state', 1)->first();
    }

    public function findByIdcard($idcard)
    {
        return FamilyMemberModel::where('idCard', $idcard)->where('state', 1)->first();
    }
}
